package com.jeff.tianti.controller;

import com.jeff.tianti.cms.dto.CourseQueryDTO;
import com.jeff.tianti.cms.dto.font.TeachQueryDTO;
import com.jeff.tianti.cms.entity.Course;
import com.jeff.tianti.cms.entity.Teach;
import com.jeff.tianti.cms.service.CourseService;
import com.jeff.tianti.cms.service.TeachService;
import com.jeff.tianti.common.PageBean;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/teach")
@CrossOrigin(maxAge = 3600)
public class TeachController {
    @Autowired
    TeachService teachService;
    @Autowired
    CourseService courseService;

    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AjaxResult index(@RequestBody PageBean pageBean) {
        PageModel<Map<String, Object>> teachPage = teachService.queryTeachList(pageBean);
        return AjaxResult.setSuccessPageModelDate(teachPage);
    }

    @RequestMapping(value = "/detail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AjaxResult detail(@RequestBody TeachQueryDTO teachQueryDTO) {
        Teach teach = teachService.find(teachQueryDTO.getId());
        return AjaxResult.setSuccessData(teach);
    }

    @RequestMapping(value = "/courseList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AjaxResult getCourseListUnderTeach(@RequestBody CourseQueryDTO teachQueryDTO) {
        PageModel<Map<String, Object>> coursePageModel = courseService.queryCourseList(teachQueryDTO);
        return AjaxResult.setSuccessPageModelDate(coursePageModel);
    }


}
